import { cooperationBehavior } from "../../../../behaviors/cooperation";
import { houseInfoBehavior } from "../../../../behaviors/houseInfo";
import { userInfoBehavior } from "../../../../behaviors/userInfo";
import { getActiveStr } from "../../../../utils/utilsNew";
const computedBehavior = require('miniprogram-computed')

// pages/im/com/preview-house-item/preview-house-item.js
Component({
  behaviors: [cooperationBehavior, houseInfoBehavior, userInfoBehavior, computedBehavior],

  /**
   * 组件的属性列表
   */
  properties: {
    cooperationId: {
      type: String,
      default: "",
    },
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    model: {},
    jjrVO: {},
    _cooperationId: '', //缓存
  },

  observers: {
    cooperationId(cooperationId) {
      if (!cooperationId) return;
      if (this.data._cooperationId == cooperationId) return;
      this.data._cooperationId = cooperationId;

      this.getInfoByCooperationId(cooperationId).then((content) => {
        if (!content) return
        const vo = { ...content.hmCooperationDelVO }
        vo._priceText = this.getPriceText(vo)
        vo._imgUrl = content.houImageVO.length!==0? content.houImageVO[0].url:'/images/defaultImgSmall.jpg'
        vo._type = this.getHouseType(vo)
        vo._resblockName = getActiveStr(vo.resblockName, 14)
        
        this.setData({
          model: vo,
          jjrVO: this.formatAuthenticatedInfo(content.jjrVO)
        });
      })
    }
  },
  
  lifetimes: {
    attached: function () {
      
    },

    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleHouseDetail() {
      wx.navigateTo({
        url: `/pages/house/RentalHouseDetail/teamworkHouseDetail/teamworkHouseDetail?cooperationId=${this.data.cooperationId}`,
      });
    }
  },
});
